#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <string.h>
using namespace std;

int n;
int a[100];
int last[100];
int ans = 1e9 + 10;

int check(int eps)
{
    int tans = a[1] - eps;
    for (int i = 2; i <= n; i++)
    {
        if (abs(a[i] - last[i - 1] - 1) <= tans)
        {
            last[i] = last[i - 1] + 1;
        }
        else
        {
            if (a[i] >= last[i - 1] + 1)
            {
                last[i] = a[i] - tans;
            }
            else
            {
                return -1; // eps太小
            }
            if (last[i] <= last[i - 1])
            {
                return -1;
            }
        }
    }

    return 1;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int left = 1, right = a[1];
    last[1] = 1;
    while (left <= right)
    {
        int mid = (left + right) / 2;
        int res = check(mid);
        if (res == 1)
        {
            ans = min(ans, a[1] - mid);
            left = mid + 1;
        }
        else if (res == -1)
        {
            right = mid - 1;
        }
        else ;
    }
    cout << ans << endl;
    //system("pause");
    return 0;
}